package action.pojo;

import java.io.Serializable;
import org.apache.commons.net.ftp.FTPFile;
import action.util.Tool;
import android.graphics.drawable.Drawable;

@SuppressWarnings("serial")
public class FtpConnect implements Serializable{

	private int idftpconnect;
	private String hostname;
	private int port;
	private String username;
	private String password;
	private String infodetail="";
	private Long totalsize;
	private FTPFile ftpFile;
	private String path;
	private Drawable icon;
	private boolean isFavorite;
	private int isFolder;
	private int idfavorite;
	private String name;
	private boolean checked=false;

	
	public int getIdftpconnect() {
		return idftpconnect;
	}
	public void setIdftpconnect(int idftpconnect) {
		this.idftpconnect = idftpconnect;
	}
	public String getHostname() {
		return hostname; 
	}
	public void setHostname(String hostname) {
		this.hostname = hostname;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	public void setInfodetail(String infodetail) {
		this.infodetail = infodetail;
	}
	public String getInfodetail(String foldername,String filename) {
		if(ftpFile.isDirectory()){
			infodetail = "";
		}
		else if(ftpFile.isFile()){
			if(this.getTotalsize()<1024){
				infodetail=this.getTotalsize() + " Bytes | "+ Tool.format1.format(this.getFtpFile().getTimestamp().getTime());
			}else{
				infodetail=(this.getTotalsize() / (1024)) + " KB | "+ Tool.format1.format(this.getFtpFile().getTimestamp().getTime());
			}
		}
		return infodetail;
	}
	
	private String getChildFile(String foldername, String filename) {
		int f = 0, fd = 0;
		
		try {
			FTPFile[] dir =  Tool.client.listFiles(Tool.getFTPPath(Tool.ftp_path));
			for (FTPFile file : dir) {
				if (file.isDirectory()) {
					fd++;
				} else {
					f++;
				}
			}
		} catch (NullPointerException e) {
			return fd + " " + foldername + " | " + f
					+ " " + filename;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fd + " " + foldername + " | " + f + " "
				+ filename;
	}
	
	public void setTotalsize(Long totalsize) {
		this.totalsize = totalsize;
	}
	public Long getTotalsize() {
		if(ftpFile.isFile()){
			totalsize = ftpFile.getSize();
		}else{
			totalsize = Tool.totalSizeFTP(ftpFile,getPath());
		}
		return totalsize;
	}
	
	public void setFtpFile(FTPFile ftpFile) {
		this.ftpFile = ftpFile;
	}
	public FTPFile getFtpFile() {
		return ftpFile;
	}
	public void setPath(String path){
		this.path = path;
	}
	public String getPath(){
		return path;
	}
	@Override
	public String toString() {
		return this.hostname;
	}
	public void setIcon(Drawable icon) {
		this.icon = icon;
	}
	public Drawable getIcon() {
		return icon;
	}
	public void setFavorite(boolean isFavorite) {
		this.isFavorite = isFavorite;
	}
	public boolean isFavorite() {
		return isFavorite;
	}
	public void setIsFolder(int isFolder) {
		this.isFolder = isFolder;
	}
	public int getIsFolder() {
		return isFolder;
	}
	public void setIdfavorite(int idfavorite) {
		this.idfavorite = idfavorite;
	}
	public int getIdfavorite() {
		return idfavorite;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}
	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}
}
